#include <vector>
using namespace std;
class Solution
{
public:
    int pivotIndex(vector<int> &nums)
    {
        int right_sum = 0;
        for (auto &e : nums)
            right_sum += e;
        int left_sum = 0;
        int i = 0;
        for (i = 0; i < nums.size(); ++i)
        {
            right_sum -= nums[i];
            if (left_sum == right_sum)
                break;
            left_sum += nums[i];
        }
        if (i == nums.size())
            return -1;
        else
            return i;
    }
};